package com.fzb.forum4j.controller;

import java.util.Date;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;

import com.fzb.forum4j.po.UserDetails;
import com.fzb.forum4j.service.api.IUserDetailsService;

@Controller("userDetailsAction")
public class UserDetailsAction extends CommonsAction<UserDetails>{
 
	
	/**
	 * 用户详细信息的管理
	 */
	private static final long serialVersionUID = 1L;
	@Resource(name="userDetailsServiceImpl")
	private IUserDetailsService userDetailsService;
	
	public String saveHeader(){
		String fileName=new Date().getTime()+".jpg";
		getT().setUser(getUserMsg());
		getQmd().setT(userDetailsService.loadUserDetailsByUser(getUserMsg()));
		System.out.println(getT());
		getT().setHeaderFileName(fileName);
		
		getT().setUserId(getUserMsg().getUserId());
		getT().getUser().setUserId(getUserMsg().getUserId());
		//保存更改后的信息
		modify();

		
		copyFile(getT().getHeader(), "header", fileName);
		return "saveHeader_success";
	}
	
	public String uploadHeader(){
		return "uploadHeader";
	}
	
	public String homeSetting(){
		UserDetails u=getQmd().getT();
		
		getT().setUser(getUserMsg());
	
		getQmd().setT(userDetailsService.loadUserDetailsByUser(getUserMsg()));
		getQmd().getData().put("userDetails", getQmd().getT());
		return "homeSetting";
	}
	
	public String saveHomeSetting(){
		UserDetails u=userDetailsService.loadUserDetailsByUser(getUserMsg());
		getQmd().getT().setUser(getUserMsg());
		
		getQmd().setT(u);
		getQmd().getT().getUser().setDetails(u);
		getQmd().getT().setUserId(36);
		modify();
		return "success";
	}
}
